package com.firefighting.util;

import java.util.Calendar;

/**
 * @author Liuxc
 * 
 * @function 判断合同执行日期界限
 * */
public class ContractTimeLimit {

	/**
	 * @author Liuxc
	 * 
	 * @function 界定合同开始月
	 * 
	 * */
	public static int getStartMonth(Calendar startTime){
		int startMonth = startTime.get(Calendar.MONTH);//合同开始月
		int startDay = startTime.get(Calendar.DAY_OF_MONTH);//合同开始日
		int DaysOfMonth = startTime.getActualMaximum(Calendar.DAY_OF_MONTH);
		int month = startMonth+1;
		System.out.println("DaysOfMonth "+DaysOfMonth);
		System.out.println("startDay  "+startDay);
		if((DaysOfMonth - startDay) > 7){
			return month;
		}else{
			return month+1;
		}
		
	}
	/**
	 * @author Liuxc
	 * 
	 * @function 界定合同结束月
	 * 
	 * */
	public static int getEndMonth(Calendar endTime){
		int endMonth = endTime.get(Calendar.MONTH);//合同结束月
		int endDay = endTime.get(Calendar.DAY_OF_MONTH);//合同结束日
		int DaysOfMonth = endTime.getActualMaximum(Calendar.DAY_OF_MONTH);
		int month = endMonth+1;
		System.out.println("DaysOfMonth "+DaysOfMonth);
		System.out.println("endDay  "+endDay);
		if(endDay > 7){
			return month;
		}else{
			return month-1;
		}
		
	}
	
	/**
	 * @author Liuxc
	 * 
	 * 界定计划开始年
	 * 
	 * 开始年的月份大于11月，则此年不生成年计划
	 * */
	public static int getStartYear(Calendar startTime){
		int startYear = startTime.get(Calendar.YEAR);//合同开始年
		int startMonth = startTime.get(Calendar.MONTH)+1;//合同开始月
		if(startMonth < 12){
			return startYear;
		}else{
			return startYear+1;
		}
		
	}
	
	
	
	/**
	 * @author Liuxc
	 * 
	 * 界定计划结束年
	 * 
	 * 结束年的月份小于2月，则此年不生成年计划
	 * */
	public static int getEndYear(Calendar endTime){
		int endYear = endTime.get(Calendar.YEAR);//合同开始年
		int endMonth = endTime.get(Calendar.MONTH)+1;//合同开始月
		if(endMonth < 2){
			return endYear-1;
		}else{
			return endYear;
		}
		
	}
	
	/**
	 * @author Liuxc
	 * 界定两日期相差月数
	 * */
	public static int calDiffMonth(Calendar startTime,Calendar endTime){
		int startYear = startTime.get(Calendar.YEAR);//合同开始年
		int endYear = endTime.get(Calendar.YEAR);//合同开始年
		int startMonth = getStartMonth(startTime);//合同开始月
		int endMonth = getEndMonth(endTime);//合同结束月
		return (endYear - startYear)*12 + endMonth - startMonth;
	}
	
	/**
	 * @author Liuxc
	 * 
	 * 界定季度计划开始月
	 * 
	 * 
	 * */
	public static int getStartMonthOfSeason(Calendar startTime){
		
		
		return 0;
		
	}
}
